package com.example.spring_forum.controller;

import com.example.spring_forum.common.AppResult;
import com.example.spring_forum.exception.model.Board;
import com.example.spring_forum.services.IBoardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "板块接口")
@Slf4j //日志
@RestController
@RequestMapping("/board")
public class BoardController {

    @Resource
    private IBoardService boardService;

 //从配置文件读取相关板块的个数，如果没有读取到，默认为9
    @Value("${forum_project.index.board-num:9}")
    private Integer IndexBoardNum;

    @ApiOperation("获取板块列表")
    @GetMapping("/topList")
      public AppResult<List<Board>>  topList(){

        System.out.println("已经进入后端");
        log.debug("主页中显示板块的个数："+IndexBoardNum);
        //调用service
        List<Board> result=boardService.selectByNum(IndexBoardNum);

        return AppResult.success(result);

    }
    @ApiOperation("获取板块详情")
    @GetMapping("/getById")
    public AppResult<Board> getBoardInfo(@ApiParam("板块id")@RequestParam("id")@NonNull Long id){

      Board board=boardService.selectById(id);

      return AppResult.success(board);

    }

}
